﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Texfina.BOQry.Co;
using System.Collections;
using Texfina.Core.Common;
using Texfina.Core.Web;

namespace CO
{
    public partial class wfOrdenCompraBnd : System.Web.UI.Page
    {
        string estado;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                chkPendiente.Checked = true;
                btnNuevo.ImageUrl = Constants2.ConstMenuControlValue.BUTTON_NEW;
                WebHelper.LoadListControl2(dbPlanta, BLocal.Local_qry01(), "ds_local", "id_local");
                LlenarGrid();

            }
        }


        private void Evaluar()
        {

            if (chkPendiente.Checked == true)
            {
                estado = Constants2.ConstEstadoOC.Pendiente;
            }
            else if (chk_nAutoriza.Checked == true)
            {
                estado = Constants2.ConstEstadoOC.nPendiente;
            }
            else
            {
                estado = Constants2.ConstEstadoOC.Autorizado;
            }
        }

        private void LlenarGrid()
        {
            try
            {
                Evaluar();
                //periodo llenar con sesion

                gvList.DataSource = BOrdenCompra.OrderCompra_qry03("2013", txtIdOrdenCompra.Text, txtProveedor.Text, (ucControlFecha1.Text), (ucControlFecha2.Text), dbPlanta.SelectedValue, estado);

                gvList.DataBind();
            }
            catch (Exception ex)
            {
                //Response.Write(ex.ToString());
            }

        }

        protected void btnBuscar_Click(object sender, EventArgs e)
        {
            LlenarGrid();
        }

        protected void gvList_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            switch (e.CommandName)
            {
                case "Detalle":
                    string Id_ordenco = (string)e.CommandArgument;
                    Hashtable htDatos = new Hashtable();
                    htDatos.Add("Id_ordenco", Id_ordenco);
                    htDatos.Add("in_ventana", "1");
                    Session["htaOcompra"] = htDatos;
                    Response.Redirect("wfOrdenCompra.aspx");
                    break;
                case "cmdadd":
                    string id_oc = (string)e.CommandArgument;
                    Hashtable htDatos1 = new Hashtable();
                    htDatos1.Add("Id_ordenco", id_oc);
                    htDatos1.Add("in_ventana", "1");
                    Session["htaOC"] = htDatos1;
                    Response.Redirect("WfOrdenCompraFactura.aspx");
                    break;
                case "cmdaddFact":

                    string id_ocfac = (string)e.CommandArgument;
                    Hashtable htDatos2 = new Hashtable();
                    htDatos2.Add("Id_ordenco", id_ocfac);
                    htDatos2.Add("in_ventana", "1");
                    Session["htaOCFac"] = htDatos2;
                    Response.Redirect("wfFactura.aspx");

                    break;
            }
        }

        protected void btnNuevo_Click(object sender, ImageClickEventArgs e)
        {
            Session["htaOcompra"] = null;
            Hashtable HtaDatos = new Hashtable();
            Session["htaOcompraNuevo"] = HtaDatos;
            Response.Redirect("wfOrdenCompra.aspx");
        }

    }
}